package space.enemy;

import org.anddev.andengine.engine.handler.physics.PhysicsHandler;
import org.anddev.andengine.entity.scene.Scene;
import org.anddev.andengine.entity.sprite.Sprite;
import org.anddev.andengine.opengl.texture.region.TextureRegion;

public class Bullet extends Sprite{
	
	private PhysicsHandler physicsHandler;
    private boolean fire;
	

	private static final int BULLET_VELOCITY = 100;



	public Bullet(final TextureRegion pTextureRegion, final Scene pScene) {
	    	// Initially, create the bullet off-screen.
	    	super(0, 0, pTextureRegion);
	    	this.setVisible(false);	
	    
			pScene.getLastChild().attachChild(this);
			physicsHandler = new PhysicsHandler(this);
			this.registerUpdateHandler(physicsHandler);
	        //pScene.registerUpdateHandler(this);            
	    }
	public boolean isFire() {
		return fire;
	}


	public void setFire(boolean fire) {
		this.fire = fire;
	}

	  
	  public void update(){
		  if(fire==true){
			  
			  this.setVisible(true);
			  physicsHandler.setVelocity(0, -BULLET_VELOCITY);
			  
			  if (this.getY() < 0) {//???????????
	    			fire = false;
			  }
			  
		  }
	  }
	  public void reset() {
		   fire = false;
		   physicsHandler.setVelocityY(0);    	 
		   this.setVisible(false);
	    }

}
